package com.suning.sawp.service.impl.oa;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.suning.sawp.constants.LoggerConstants;
import com.suning.sawp.intf.oa.OaService;
import com.suning.sawp.service.util.HttpClientUtil;

/**
 * 
 * <br> 
 * 〈功能详细描述〉
 *
 * @author 13071470
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service
public class OaServiceImpl implements OaService{
    
    
    private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstants.SAWP_INTEGRATION);
    
    @Value("#{settingConfig[oa_url]}")
    String oaUrl;

    @Override
    public boolean checkOaPwd(String userId, String password) {
       if(StringUtils.isNotBlank(userId) && StringUtils.isNotBlank(password)){
           Map<String, String> fromParams = new HashMap<String, String>();
           fromParams.put("username", userId);
           fromParams.put("password", password);
           String resp = "";
           try{
               resp = HttpClientUtil.postData(oaUrl, fromParams);
               return StringUtils.isNotBlank(resp) && Boolean.parseBoolean(resp);
           }catch(Exception e){
               LOGGER.error("调用OA系统校验员工密码异常,工号:"+userId,e);
           }
       }
        return false;
    }

}
